package com.lcf.system.controller;

import com.lcf.framework.annotation.PermissionCheck;
import com.lcf.system.dto.menu.SysMenuDTO;
import com.lcf.system.service.SysMenuService;
import com.lcf.system.vo.menu.SysMenuTreeVO;
import com.lcf.system.vo.menu.SysMenuVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.lcf.framework.enums.PermissionEnum.*;

/**
 * 菜单(SysMenu)表控制层
 *
 * @author lcf
 * @since 2025-02-25 12:24:22
 */
@Tag(name = "菜单")
@RestController
@RequestMapping("sysMenu")
public class SysMenuController {
    @Resource
    private SysMenuService sysMenuService;

    /**
     * 新增菜单
     */
    @Operation(summary = "新增菜单")
    @PermissionCheck(SYS_MENU_ADD)
    @PostMapping
    public void add(@Validated @RequestBody SysMenuDTO dto) {
        sysMenuService.add(dto);
    }

    /**
     * 编辑
     */
    @Operation(summary = "编辑菜单")
    @PermissionCheck(SYS_MENU_EDIT)
    @PatchMapping("{id}")
    public void update(@PathVariable @Schema(description = "菜单id") long id,
                       @Validated @RequestBody SysMenuDTO dto) {
        sysMenuService.update(id, dto);
    }

    /**
     * 删除
     */
    @Operation(summary = "删除菜单")
    @PermissionCheck(SYS_MENU_DEL)
    @DeleteMapping("{id}")
    public void delete(@PathVariable @Schema(description = "菜单id") long id) {
        sysMenuService.delete(id);
    }

    /**
     * 获取全部菜单树
     */
    @Operation(summary = "获取全部菜单树")
    @PermissionCheck(SYS_MENU_TREE)
    @GetMapping("tree")
    public List<SysMenuTreeVO> getTree() {
        return sysMenuService.getTree();
    }

    /**
     * 获取当前用户有权限查看的菜单树
     */
    @Operation(summary = "获取当前用户菜单树")
    @GetMapping("user/tree")
    public List<SysMenuTreeVO> getUserTree() {
        return sysMenuService.getUserTree();
    }

    /**
     * 获取菜单详情
     */
    @Operation(summary = "获取菜单详情")
    @PermissionCheck(SYS_MENU_DETAIL)
    @GetMapping("{id}")
    public SysMenuVO getDetail(@PathVariable @Schema(description = "菜单id") long id) {
        return sysMenuService.getDetail(id);
    }
}

